function FontModel(data) {	
	this.name = data.name;
	this.family = data.family == null ? 'Standard':data.family;
	this.homepage = data.homepage;
	this.chance = ko.observable(data.chance);	
	this.kanjiOnly = ko.observable(data.kanjiOnly);	
	this.css = data.family == null ? null : "font-family: "+data.family;
}

var OptionsModel = function(){
	
	var self = this;		
	var optionsStore = new OptionsStore();
	var data = optionsStore.load();		
			
	self.version = 1;	
	self.replaceOnQuestionBox = ko.observable(data.replaceOnQuestionBox);
	self.replaceOnAnswers = ko.observable(data.replaceOnAnswers);
	self.replaceOnAnswersMax = ko.observable(data.replaceOnAnswersMax);
	self.randomizeOncePerQuestion = ko.observable(data.randomizeOncePerQuestion);
	
	self.fonts = ko.observableArray([]);
	var mappedFonts = ko.utils.arrayMap(data.fonts, function(f) { return new FontModel(f) });
	self.fonts(mappedFonts);
	
	self.save = function () {
		optionsStore.save(ko.toJS(self));
	};

	self.copyright = ko.computed(function () {
		var list = [];
		var fonts = self.fonts();
		for (var i = 0, len = fonts.length; i < len; i++) {
			if (fonts[i].family != 'Standard')
				list.push(fonts[i]);
		}
		return list;
	});
}

ko.applyBindings(new OptionsModel());